package cn.javabb.service;

import cn.javabb.common.entity.Student;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc:
 * @author: javabb (javabob(a)163.com)
 * @create: 2020/08/15 14:25
 */
@Component
public class StudentClientFallbackFactory implements FallbackFactory<StudentClientService> {
    @Override
    public StudentClientService create(Throwable throwable) {
        // 服务降级的实现方法
        return new StudentClientService() {
            @Override
            public Student query(Integer id) {
                return null;
            }

            @Override
            public List<Student> all() {
                return null;
            }

            @Override
            public boolean save(Student student) {
                return false;
            }

            @Override
            public boolean delete(Integer id) {
                return false;
            }

            @Override
            public Map<String, Object> getInfo() {
                Map<String, Object> map = new HashMap<>();
                map.put("code", 500);
                map.put("info", "服务器错误");
                return map;
            }
        };
    }
}
